package com.example.demo.websoket.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 彭长云
 * @Description:
 * @date 2019/2/27 17:23
 */
@Configuration
public class RabbitMqConfig {
    //订阅模式路由
    public final static String WEBSOCKET_MQ_EXCHANGE = "websocket.fanout.exchange";

    /**
     * 用于websocket发送消息的路由
     */
    @Bean
    public FanoutExchange websocketFanoutExchange(){
        return new FanoutExchange(WEBSOCKET_MQ_EXCHANGE);
    }

    /**
     * 消息订阅匿名队列
     */
    @Bean
    public Queue websocketQueue(){
        return new AnonymousQueue();
    }

    /**
     * 绑定队列到路由
     */
    @Bean
    public Binding bindingWebSocketQueue(){
        return BindingBuilder.bind(websocketQueue()).to(websocketFanoutExchange());
    }
}
